package com.pansoft.androidalldemo.router;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

/**
 * Created by meijun on 17-5-5.
 */

public class Router {

    private Context mContext;
    private final Intent intent;

    public Router(Context context) {
        this.mContext = context;
        intent = new Intent();
    }

    public static Router from(Context context) {

        return new Router(context);
    }

    private Class clazz;

    public Router setAction(Class clazz) {
        this.clazz = clazz;
        return this;
    }

    public void navigation() {
        intent.setClass(mContext,clazz);
        mContext.startActivity(intent);
    }
    public void navigationForResult(int requestCode){
        intent.setClass(mContext,clazz);
        if(mContext instanceof  Activity){
            ((Activity) mContext).startActivityForResult(intent,requestCode);
        }

    }

    public Router setString(String key, String value) {

        intent.putExtra(key,value);

        return this;
    }

    public Router setInt(String key, int value) {

        intent.putExtra(key,value);

        return this;
    }
}